from django.contrib import admin
from django.forms import ModelForm
from django.forms.widgets import TextInput

from .models import Background, Category, IDPhoto

# Register your models here.

class BackgroundForm(ModelForm):
    class Meta:
        model = Background
        fields = '__all__'
        widgets = {
            'primary_color': TextInput(attrs={'type': 'color'}), #type:color 是固定值
            'secondary_color': TextInput(attrs={'type': 'color'}), #type:color 是固定值
        }

@admin.register(Background)
class BackGroundAdmin(admin.ModelAdmin):
    # """证件照背景色管理"""
    form = BackgroundForm

    list_display = ('id','name','primary_color','secondary_color',)
    list_display_links=('id','name',)
    #按字段排序
    ordering=('create_time',)
    sortable_by = ('id',)
    

@admin.register(Category)
class CategoryAdmin(admin.ModelAdmin):
    """证件照类型管理"""
    list_display=('id','name','desc',)
    list_display_links=('id','name',)

@admin.register(IDPhoto)
class IDPhotoAdmin(admin.ModelAdmin):
    """证件照尺寸管理"""
    list_display=('id','name','width','height','category','is_common',)
    list_display_links=('id','name',)
    list_editable = ('is_common',)

    fieldsets = [(None,{"fields":["category","name","width","height","top_dis","edge_dis","dpi",("is_idphoto","is_common")]})]#[(None,{"fields":("category","name","width","height","top_dis","edge_dis","dpi",("is_idphoto","is_common"))},)


